package com.wedo.mall.fragment;

import android.os.Bundle;
import android.view.View;
import android.widget.FrameLayout;
import com.e.library.activity.EActivity;
import com.e.library.fragment.EFragment;
import com.wedo.mall.R;
import com.wedo.mall.entity.AttrItem;
import com.wedo.mall.entity.Goods;
import com.wedo.mall.widget.AttrWidget;
import java.util.Collection;
import butterknife.BindView;
import butterknife.OnClick;

/**
 * 选择商品属性
 * Created by e on 2017/7/10.
 */

public class AttrFragment extends EFragment<EActivity> {

    public AttrWidget widget = new AttrWidget();
    @BindView(R.id.fl_root) FrameLayout fl_root;

    public static AttrFragment with(Goods goods){
        Bundle bundle = new Bundle();
        bundle.putParcelable("goods",goods);
        AttrFragment fragment = new AttrFragment();
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    protected int layout() {
        return R.layout.fragment_attr;
    }

    @Override
    protected void onFragmentCreated(View contentView, Bundle bundle) {

        Goods goods = getArguments().getParcelable("goods");
        widget.init(getContext(),goods);
        widget.attach(fl_root);
    }


    @OnClick(R.id.fl_root)
    protected void onRootClick(){
        dismiss();
    }

    private void dismiss(){
        activity().getSupportFragmentManager().beginTransaction().hide(this).commit();
    }

    public interface OnSelectedAttr{
        void onSelected(String id,int number,Collection<AttrItem> attrs);
    }
}
